﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WuDada.Core.Post;
using WuDada.Core.Post.Service;
using WuDada.Core.Post.Domain;
using System.Text;

public partial class UserControl_RightTeam : System.Web.UI.UserControl
{
    private PostFactory m_PostFactory;
    private IPostService m_PostService;

    //醫師陣容 m_NodeId = 8
    private readonly int m_NodeId = 8;

    protected void Page_Load(object sender, EventArgs e)
    {
        m_PostFactory = new PostFactory();
        m_PostService = m_PostFactory.GetPostService();

        if (!IsPostBack)
        {
            FillTeam();
        }
    }

    private void FillTeam()
    {
        //搜尋條件
        Dictionary<string, string> conditions = new Dictionary<string, string>();
        conditions.Add("NodeId", m_NodeId.ToString());
        conditions.Add("Flag", "1");
        conditions.Add("IsRecommend", true.ToString());

        RepeaterTeam.DataSource = m_PostService.GetPostList(conditions);
        RepeaterTeam.DataBind();
    }

    protected void RepeaterTeam_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemIndex != -1)
        {
            Control ctrl = e.Item;
            PostVO postVO = (PostVO)e.Item.DataItem;
            
            ////主治項目
            StringBuilder sbIndications = new StringBuilder();
            if (!string.IsNullOrEmpty(postVO.CustomField2))
            {
                string[] list = postVO.CustomField2.Split(new Char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (string s in list)
                {
                    sbIndications.AppendFormat("‧{0}<br />", s);
                }
            }

            UIHelper.SetLiteralText(ctrl, "ltlIndications", sbIndications.ToString());
        }
    }
}